//328. 奇偶链表

function ListNode(val, next) {
      this.val = (val===undefined ? 0 : val)
      this.next = (next===undefined ? null : next)
}
 
/**
 * @param {ListNode} head
 * @return {ListNode}
 */
var oddEvenList = function(head) {
    let index =1;
    let p = head;
    let head_odd = new ListNode(-1,null);
    let head_even = new ListNode(-1,null);
    let p_odd = head_odd;
    let p_even = head_even;
    while(p!==null){
        if(index&1){//odd
            p_odd.next = p;
            p_odd = p;
        }else{//even
            p_even.next = p;
            p_even = p;
        }
        let _p = p;
        p=p.next;
        _p.next=null;
        index++;
    }
    p_odd.next =  head_even.next;
    return head_odd.next;
};